Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the StateMachine implementation to remove the virtual set_on method from the IStateMachine interface and transitions from a runtime-based nested machine management approach to a compile-time tuple-based approach. The changes improve type safety and potentially performance by leveraging compile-time configuration.
Changes:
- Removed
is_onfield andset_on()virtual method from StateMachine and its interface - Replaced
FixedVectortype alias with directStaticVectorusage - Introduced compile-time tuple-based nested machine management with
NestedMachineBindingand helper functions - Added self-transition validation in State constructor
- Refactored state change logic into a single
perform_state_change()method - Updated HeapStateOrder and StackStateOrder to remove
is_onchecks
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Inc/ST-LIB_LOW/StateMachine/StateMachine.hpp | Core refactoring: removed is_on/set_on, replaced dynamic nested machines with compile-time tuple approach, added self-transition validation, introduced StateMachineHelper namespace |
| Inc/ST-LIB_LOW/StateMachine/StackStateOrder.hpp | Removed is_on checks from process() and parse() methods |
| Inc/ST-LIB_LOW/StateMachine/HeapStateOrder.hpp | Removed is_on checks from process() and parse() methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… condition is true
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No more virtual methods are called in the StateMachine. Now only ProtectionManager and StateOrders call this methods(1 time every a lot of time).
Now the state machine uses std::tuple to store the nested state machines' pointers allowing zero overhead, no vtable, and easy declaration for the programmer(compiler magic).
The only change that the user will notice is going from sm.add_state_machine(nestes_sm), to:
auto nested = StateMachineHelper::add_nesting(operational_state, Operational_State_Machine);
auto sm = make_state_machine(States_PCU::Connecting,
StateMachineHelper::add_nested_machines(nested),
connecting_state,
operational_state,
fault_state
);
Also this pr adds additional checks on compile time(like declaring the state machine with the same state multiple times), as well as simulator tests for the stlib simulator. This test check functionality and the existence of compile time errors(like duplicating a state when creating the state machine for example, if this compiles the test will fail)